package com.lanou3g.code0418.control;

import com.lanou3g.code0418.methods.ThreadUtil;

/**
 * Created by dllo on 18/4/18.
 */
public class Test02 {

    private static int sum = 0;

    public static void main(String[] args) {


        System.out.println(Thread.currentThread());
        Thread a = new Thread(new Runnable() {


            @Override
            public void run() {

                System.out.println(Thread.currentThread());
                for (int i = 0; i < 10; i++) {
                    sum += i;
                    System.out.println(i);

                    ThreadUtil.sleep(1000);
                }
            }
        },"线程名");
        a.start();

        //ThreadUtil.sleep(15000);
        System.out.println("jdfghdfkjgdfgd");

        try {

            //调用线程对象的join方法，可以让当前线程等待线程对象执行完毕后再继续执行
            //在哪个线程中调用的 线程对象.join(),哪个线程就去等

            a.join(1000);  //把a放到主线程中( 有参数是指定等待时间)
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        System.out.println("主线程执行完毕" + sum);


    }
}
